| Conditions | 3 |
| Paths | 17 |
| Total Lines | 72 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /*jslint |
||
| 34 | Url.parseMarkers = function (urlarg) { |
||
| 35 | 'use strict'; |
||
| 36 | |||
| 37 | if (!urlarg) { |
||
| 38 | return []; |
||
| 39 | } |
||
| 40 | |||
| 41 | var data; |
||
| 42 | |||
| 43 | // ID:COODRS:R(:NAME)?|ID:COORDS:R(:NAME)? |
||
| 44 | // COORDS=LAT:LON or DEG or DMMM |
||
| 45 | if (urlarg.indexOf("*") >= 0) { |
||
| 46 | data = urlarg.split('*'); |
||
| 47 | } else { |
||
| 48 | /* sep is '|' */ |
||
| 49 | data = urlarg.split('|'); |
||
| 50 | } |
||
| 51 | |||
| 52 | return data.map(function (dataitem) { |
||
| 53 | dataitem = dataitem.split(':'); |
||
| 54 | if (dataitem.length < 3 || dataitem.length > 6) { |
||
| 55 | return null; |
||
| 56 | } |
||
| 57 | |||
| 58 | var m = { |
||
| 59 | alpha: dataitem[0], |
||
| 60 | id: alpha2id(dataitem[0]), |
||
| 61 | name: null, |
||
| 62 | coords: null, |
||
| 63 | r: 0, |
||
| 64 | color: "" |
||
| 65 | }, |
||
| 66 | index = 1, |
||
| 67 | lat, |
||
| 68 | lon; |
||
| 69 | |||
| 70 | if (m.id < 0) { |
||
| 71 | return null; |
||
| 72 | } |
||
| 73 | |||
| 74 | lat = parseFloat(dataitem[index]); |
||
| 75 | lon = parseFloat(dataitem[index + 1]); |
||
| 76 | if (Coordinates.valid(lat, lon)) { |
||
| 77 | index += 2; |
||
| 78 | m.coords = new google.maps.LatLng(lat, lon); |
||
| 79 | } else { |
||
| 80 | m.coords = Coordinates.fromString(dataitem[index]); |
||
| 81 | index += 1; |
||
| 82 | } |
||
| 83 | if (!m.coords) { |
||
| 84 | return null; |
||
| 85 | } |
||
| 86 | |||
| 87 | m.r = App.repairRadius(parseFloat(dataitem[index]), 0); |
||
| 88 | index = index + 1; |
||
| 89 | |||
| 90 | if (index < dataitem.length && |
||
| 91 | (/^([a-zA-Z0-9\-_]*)$/).test(dataitem[index])) { |
||
| 92 | m.name = dataitem[index]; |
||
| 93 | } |
||
| 94 | |||
| 95 | index = index + 1; |
||
| 96 | if (index < dataitem.length && |
||
| 97 | (/^([a-fA-F0-9]{6})$/).test(dataitem[index])) { |
||
| 98 | m.color = dataitem[index]; |
||
| 99 | } |
||
| 100 | |||
| 101 | return m; |
||
| 102 | }).filter(function (thing) { |
||
| 103 | return thing !== null; |
||
| 104 | }); |
||
| 105 | }; |
||
| 106 | |||
| 154 |